macro_rules! option_doc {
    ($($name:literal:$value:expr),*) => {
        {
            let mut res_doc = wither::bson::Document::new();
            $(
                if let Some(ref some_value) = $value {
                    res_doc.insert($name,some_value);
                }
            )*
            res_doc
        }
    };
}
macro_rules! get_path_param {
    ($params:ident,$param_name:ident,$err_name:ident) => {{
        $params.$param_name.ok_or($crate::AppError::Status(
            actix_http::StatusCode::BAD_REQUEST,
            $crate::errors::cons_error::$err_name.into(),
        ))?
    }};
}
macro_rules! define_request_struct {
    ($s_name:ident {
        $(
            $(#[$field_meta:meta])*
            $field:ident:$field_type:ty
        ),*$(,)*
    }) => {
        #[derive(Debug,Clone,serde::Serialize,serde::Deserialize)]
        pub struct $s_name {
            $(
                $(#[$field_meta])*
                pub $field :$field_type,
            )*
        }
    };
    (default| $s_name:ident {
        $(
            $(#[$field_meta:meta])*
            $field:ident:$field_type:ty
        ),*$(,)*
    }) => {
        #[derive(Debug,Clone,serde::Serialize,serde::Deserialize)]
        #[serde(default="Default::default")]
        pub struct $s_name {
            $(
                $(#[$field_meta])*
                pub $field :$field_type,
            )*
        }
    }
}
macro_rules! define_filter_request_struct {
    ($s_name:ident {
        $(
            $(#[$field_meta:meta])*
            $field:ident:$field_type:ty
        ),*$(,)*
    }) => {
        #[derive(Debug,Clone,serde::Serialize,serde::Deserialize)]
        pub struct $s_name {
            $(
                $(#[$field_meta])*
                pub $field :$field_type,
            )*
            pub filter:Option<serde_json::Value>
        }
        #[allow(dead_code)]
        impl $s_name {
            pub fn get_filter_as_document(&self,no_regepx:&[&str]) -> Option<wither::bson::Document> {
                self.filter.as_ref().map(|filter|$crate::utils::db_utils::build_filter(filter,no_regepx)).flatten()
            }
            pub fn get_filter_as_document_use_default(&self) -> Option<wither::bson::Document> {
                self.get_filter_as_document(&$crate::utils::db_utils::COMMON_NO_REGEXP)
            }
        }
    };
    (default|$s_name:ident {
        $(
            $(#[$field_meta:meta])*
            $field:ident:$field_type:ty
        ),*$(,)*
    }) => {
        #[derive(Debug,Clone,serde::Serialize,serde::Deserialize)]
        #[serde(default="Default::default")]
        pub struct $s_name {
            $(
                $(#[$field_meta])*
                pub $field :$field_type,
            )*
            pub filter:Option<serde_json::Value>
        }
        #[allow(dead_code)]
        impl $s_name {
            pub fn get_filter_as_document(&self,no_regepx:&[&str]) -> Option<wither::bson::Document> {
                self.filter.as_ref().map(|filter|$crate::utils::db_utils::build_filter(filter,no_regepx)).flatten()
            }
            pub fn get_filter_as_document_use_default(&self) -> Option<wither::bson::Document> {
                self.get_filter_as_document(&$crate::utils::db_utils::COMMON_NO_REGEXP)
            }
        }
    }
}
/// 这个默认数据更改实现是讲模型的update_time更新到当前时间
macro_rules! impl_modifyed_for_model {
    ($model:ident,$update_field:ident) => {
        impl $crate::utils::traits::ModifyModelData for $model {
            #[inline]
            fn modifyed(&mut self) -> () {
                self.$update_field = wither::bson::DateTime::now();
            }
        }
    };
}
